/*
 * @Description: 正则校验
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2024-03-06
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2025-03-17
 */
import lodash from 'lodash-es'

/**
 * 判断是否空值, 数字原路返回，其他做判断
 * @param value
 * @returns {boolean} true 为空值，false为非空
 */
export const isEmptyValue = (value: unknown): boolean => {
  switch (typeof value) {
    case 'object':
      return lodash.isEmpty(value)
    case 'number':
      return isNaN(value)
    case 'string':
      return !value
    default:
      break
  }
  return value === null || value === undefined
}

/** 手机号正则 */
// export const REG_PHONE = /^1\d{10}$/
export const REG_PHONE = /^(1|2)\d{10}$/

/**
 * 校验正则：手机号
 * @param phone 手机号
 * @returns
 */
export const validPhone = (phone: string | number) => {
  if (typeof phone === 'number') phone = phone.toString()
  return REG_PHONE.test(phone)
}

/**
 * 删除所有注释
 * @param code 代码
 * @returns
 */
export const removeAllComments = (code) => {
  return code
    .replace(/\/\/.*$/gm, '') // 删除单行注释
    .replace(/\/\*[\s\S]*?\*\//g, '') // 删除多行注释
}
